﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using control.Dal;

namespace control.Biz
{
    public class BizSanPham
    {
        public int ID { get; set; }
        public string MaSanPham { get; set; }
        public string TenSanPham { get; set; }
        public string ThongTinSanPham { get; set; }
        public string Hinh { get; set; }
        public int SoLuong { get; set; }
        public decimal GiaBan { get; set; }
        private BizLoaiSanPham loaiSanPham;
        public BizLoaiSanPham LoaiSanPham
        {
            get
            {
                return loaiSanPham;
            }
            set{loaiSanPham=value;}
        }
        public string TenLoaiSanPham
        {
            get { return loaiSanPham.TenLoai; }
        }
        public bool IsNew { get; set; }
        public string icon
        {
            get
            {
                if (IsNew == true)
                {
                    return "<img src='images/new_icon.gif' alt='' title='' />";
                }
                else
                    return "";
            }
        }
        public BizSanPham()
        {

        }
        public BizSanPham(int _ID,string _MaSanPham, string _TenSanPham, string _ThongTinSanPham, string _Hinh,int _SoLuong,decimal _GiaBan,BizLoaiSanPham _LoaiSanPham,bool _IsNew)
        {
            ID = _ID;
            MaSanPham = _MaSanPham;
            TenSanPham = _TenSanPham;
            ThongTinSanPham = _ThongTinSanPham;
            Hinh = _Hinh;
            SoLuong = _SoLuong;
            GiaBan = _GiaBan;
            LoaiSanPham = _LoaiSanPham;
            IsNew = _IsNew;
        }

        public static List<BizSanPham> GetAll()
        {
            return DalSanPham.GetAll();
        }

        public static BizSanPham GetSanPhamByID(int _ID)
        {
            return DalSanPham.GetSanPhamByID(_ID);
        }

        public static List<BizSanPham> GetNewSp()
        {
            return DalSanPham.GetNewSp();
        }

        public static List<BizSanPham> GetSanPhamByIDLoai(int _IDLoai)
        {
            return DalSanPham.GetSanPhamByIDLoai(_IDLoai);
        }

        public void Insert()
        {
            ID = DalSanPham.Insert(this);
        }

        public bool Detele()
        {
            return DalSanPham.Delete(this);
        }

        public static BizSanPham GetByID(int ID)
        {
            return DalSanPham.GetByID(ID);
        }


        public bool Update()
        {
            return DalSanPham.Update(this);
        }

        public static List<BizSanPham> Find(string loai, string sp)
        {
            return DalSanPham.Find(loai,sp);
        }

        

        public static List<BizSanPham> Getramdom(int p)
        {
            return DalSanPham.Getramdom(p);
        }

        public static List<BizSanPham> Getfeature()
        {
            return DalSanPham.Getfeature();
        }

        public static List<BizSanPham> Find(string loai, string sp, int giatu, int giaden)
        {
            return DalSanPham.Find(loai, sp,giatu,giaden);
        }
    }
}
